﻿using System;
using System.Collections;
using System.Collections.Generic;
using XLua;
public class TimeServer : BaseServer
{
    LuaFunction _luaFunction = null;
    private DateTime centuryBegin;
    public override void Init()
    {
        centuryBegin = new DateTime(1970, 1, 1, 8, 0, 0, 0);
    }

    public override void OnAddEventService()
    {
       
    }

    public override void OnDestroy()
    {
        
    }

    public override void OnRemoveEventService()
    {
        
    }

    public override void OnUpdate()
    {
       if(_luaFunction != null)
        {
            _luaFunction.Call();
        }
    }

    public void SetLuaFunction(LuaFunction luaFunction)
    {
        _luaFunction = luaFunction;
    }

    public double GetTimeTicks()
    {
        TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
        //UnityEngine.Debug.Log("GetTimeTicks:" + ts.TotalMilliseconds);
        return ts.TotalMilliseconds * 0.001;

        ////return (DateTime.Now.Ticks - centuryBegin.Ticks) * 0.00000001;
        //return (DateTime.Now.Ticks - centuryBegin.Ticks) / 10000000.0;

    }
}
